home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 50
/
Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso
/
Aminet
/
comm
/
irc
/
Babelfish.lha
/
Babelfish.amirx
next >
Wrap
Text File
|
2002-05-28
|
4KB
|
170 lines
/* Babelfish translator script for AmIRC ©2002 Michael Trebilcock */
Options Results
Signal On Syntax
Parse Arg Lang" "Text
/* Configuration */
TransOnly="0" /* Show translation only? 1 = Yes, 0 = No */
SendToWin="0" /* Send translation to active window? 1 = Yes, 0 = No */
/* End Configuration */
/** DON'T EDIT BELOW THIS LINE **/
Override="0";Nick=""
IF Left(Lang,1)="\" THEN DO
Lang=SubStr(Lang,2);Override="1"
IF Left(Text,1)="<"&Right(Word(Text,1),1)=">" THEN DO
Length=Length(Word(Text,1))
Nick=SubStr(Strip(Word(Text,1),,">"),2)
Text=SubStr(Text,Length+2)
End
End
Port=Address()
X01="0D"x
EchoTxt="Babelfish"
IF Lang=""|Lang="?"|Upper(Lang)="HELP" THEN DO
Call cEcho("Usage: /rx Babelfish <en_fr/en_de/en_it/en_pt/en_es/fr_en/de_en/it_en/pt_en/es_en/de_fr/fr_de/ru_en/en_ja/en_ko/en_zh/ja_en/ko_en/zh_en> <text>")
Call cEcho("")
Call cEcho("en_fr English to French")
Call cEcho("en_de English to German")
Call cEcho("en_it English to Italian")
Call cEcho("en_pt English to Portuguese")
Call cEcho("en_es English to Spanish")
Call cEcho("fr_en French to English")
Call cEcho("de_en German to English")
Call cEcho("it_en Italian to English")
Call cEcho("pt_en Portuguese to English")
Call cEcho("es_en Spanish to English")
Call cEcho("de_fr German to French")
Call cEcho("fr_de French to German")
Call cEcho("ru_en Russian to English")
Call cEcho("en_ja English to Japanese")
Call cEcho("en_ko English to Korean")
Call cEcho("en_zh English to Chinese")
Call cEcho("ja_en Japanese to English")
Call cEcho("ko_en Korean to English")
Call cEcho("zh_en Chinese to English")
Exit
End
Parse Var Lang SLang"_"ELang
Call Lang(SLang)
Call Lang(ELang)
EchoTxt="Babelfish"
IF ~Open(TCP,"TCP:babelfish.altavista.com/80","RW") THEN DO
Call cEcho("Unable to connect to babelfish..")
Exit
End
CR="0D"x
ToSend="doit=done&tt=urltext&urltext="Text"&url=http%3A%2F%2F&lp="Lang
Length=Length(ToSend)
Call WriteLn(TCP,"POST /tr HTTP/1.0"CR)
Call WriteLn(TCP,"Host: babelfish.altavista.com"CR)
Call WriteLn(TCP,"Content-Type: application/x-www-form-urlencoded"CR)
Call WriteLn(TCP,"Content-Length: "Length""CR)
Call WriteLn(TCP,CR)
Call WriteLn(TCP,ToSend""CR)
Output=Word(ReadLn(TCP),2)
IF Output~="200" THEN DO
Call cEcho("Unable to translate, error "Output)
Call CloseTCP()
End
Call Lang(SLang)
IF TransOnly="0" THEN Call cEcho(Text)
Call Lang(ELang)
DO UNTIL Word(Output,1)="<textarea"|Pos("td bgcolor=white",Output)>0|EOF(TCP)
Output=Strip(ReadLn(TCP),,X01)
End
IF EOF(TCP) THEN DO
EchoTxt="Babelfish"
Call cEcho("Unable to translate, server didn't accept the arguments")
Call CloseTCP()
End
IF Word(Output,1)="<textarea" THEN DO
IF Right(Output,11)="</textarea>" THEN Output=""
ELSE Output=SubStr(Output,Pos(">",Output)+1)
End
ELSE DO
Output=SubStr(Output,Pos(">",Output)+1)
Output2=Strip(ReadLn(TCP),,X01)
IF Right(Output,5)~="</td>" THEN Output=Output" "Output2
IF Right(Output2,5)~="</td>" THEN DO
DO UNTIL Right(Output2,5)="</td>"
Output2=Strip(ReadLn(TCP),,X01)
Output=Output" "Output2
End
End
IF Left(Output,1)=" " THEN Output=SubStr(Output,2)
Output=SubStr(Output,1,Length(Output)-5)
End
Success="1"
Call Algo(Output)
IF Nick~="" THEN EchoTxt=Nick
Call cEcho(Output)
Call CloseTCP()
Exit
cEcho:
IF Port="REXX" THEN SAY "«"EchoTxt"» "Arg(1)
ELSE DO
IF SendToWin="1"&Success="1"&Override="0" THEN "SAY "Arg(1)
ELSE "ECHO P="d2c(27)"b«"EchoTxt"» TEXT="Arg(1)
End
Return 0
CloseTCP:
Call Close(TCP)
Exit
Syntax:
EchoTxt="Syntax"
Call cEcho("Command on line" SIGL "returned" RC ":" errortext(rc) sourceline(SIGL))
Exit
Algo:
Output=Arg(1)
DO UNTIL Char="0"
Char=Pos("Ã",Output)
IF Char>0 THEN DO
First=SubStr(Output,1,Char-1)
Next=SubStr(Output,Char+2)
Char=d2c(c2d(SubStr(Output,Char+1,1))+64)
Output=First""Char""Next
End
End
Return 0
Lang:
SELECT
WHEN Arg(1)="en" THEN EchoTxt="English"
WHEN Arg(1)="fr" THEN EchoTxt="French"
WHEN Arg(1)="de" THEN EchoTxt="German"
WHEN Arg(1)="it" THEN EchoTxt="Italian"
WHEN Arg(1)="pt" THEN EchoTxt="Portuguese"
WHEN Arg(1)="es" THEN EchoTxt="Spanish"
WHEN Arg(1)="ru" THEN EchoTxt="Russian"
WHEN Arg(1)="ja" THEN EchoTxt="Japanese"
WHEN Arg(1)="ko" THEN EchoTxt="Korean"
WHEN Arg(1)="zh" THEN EchoTxt="Chinese"
OTHERWISE DO
EchoTxt="Babelfish"
Call cEcho("Invalid language "Arg(1))
Exit
End
End
Return 0